package cn.iocoder.yudao.module.handguard.controller.admin.orderprocessrecord;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.handguard.controller.admin.orderprocessrecord.vo.OrderRecordInfoVO;
import cn.iocoder.yudao.module.handguard.controller.app.orderprocessrecord.vo.*;
import cn.iocoder.yudao.module.handguard.controller.app.usertablesaudit.vo.UserTablesAuditRespVO;
import cn.iocoder.yudao.module.handguard.convert.orderprocessrecord.OrderProcessRecordConvert;
import cn.iocoder.yudao.module.handguard.convert.usertablesaudit.UserTablesAuditConvert;
import cn.iocoder.yudao.module.handguard.dal.dataobject.orderprocessrecord.OrderProcessRecordDO;
import cn.iocoder.yudao.module.handguard.dal.dataobject.usertablesaudit.UserTablesAuditDO;
import cn.iocoder.yudao.module.handguard.service.orderprocessrecord.OrderProcessRecordService;
import cn.iocoder.yudao.module.handguard.service.usertablesaudit.UserTablesAuditService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 审核流程记录")
@RestController
@RequestMapping("/ht/orderProcessRecord")
@Validated
public class OrderRecordController {

    @Resource
    private OrderProcessRecordService orderProcessRecordService;


    @Resource
    private UserTablesAuditService userTablesAuditService;

//    @PostMapping("/create")
//    @Operation(summary = "创建订单审核流程记录")
//    @PreAuthorize("@ss.hasPermission('hutai:order-process-record:create')")
//    public CommonResult<Long> createOrderProcessRecord(@Valid @RequestBody OrderProcessRecordCreateReqVO createReqVO) {
//        return success(orderProcessRecordService.createOrderProcessRecord(createReqVO));
//    }

//    @PutMapping("/update")
//    @Operation(summary = "更新订单审核流程记录")
//    @PreAuthorize("@ss.hasPermission('hutai:order-process-record:update')")
//    public CommonResult<Boolean> updateOrderProcessRecord(@Valid @RequestBody OrderProcessRecordUpdateReqVO updateReqVO) {
//        orderProcessRecordService.updateOrderProcessRecord(updateReqVO);
//        return success(true);
//    }

//    @DeleteMapping("/delete")
//    @Operation(summary = "删除订单审核流程记录")
//    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('hutai:order-process-record:delete')")
//    public CommonResult<Boolean> deleteOrderProcessRecord(@RequestParam("id") Long id) {
//        orderProcessRecordService.deleteOrderProcessRecord(id);
//        return success(true);
//    }

//    @GetMapping("/get")
//    @Operation(summary = "获得订单审核流程记录")
//    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@ss.hasPermission('hutai:order-process-record:query')")
//    public CommonResult<OrderProcessRecordRespVO> getOrderProcessRecord(@RequestParam("id") Long id) {
//        OrderProcessRecordDO orderProcessRecord = orderProcessRecordService.getOrderProcessRecord(id);
//        return success(OrderProcessRecordConvert.INSTANCE.convert(orderProcessRecord));
//    }

    @GetMapping("/list")
    @Operation(summary = "获得订单审核流程记录列表")
    @Parameter(name = "id", description = "订单id", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('hutai:order:query')")
    public CommonResult<Map<String,List<OrderProcessRecordRespVO>>> getOrderProcessRecordList(Long id) {
        Map<String,List<OrderProcessRecordRespVO>> listMap = orderProcessRecordService.getOrderProcessRecordListById(id);
        return success(listMap);
    }

    @GetMapping("/order-info")
    @Operation(summary = "订单审核流程详情")
    @Parameter(name = "id", description = "订单id", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('hutai:order:query')")
    public CommonResult<OrderRecordInfoVO> getOrderInfo(Long id) {
        OrderRecordInfoVO infoVO = orderProcessRecordService.getOrderInfo(id);
        return success(infoVO);
    }


    @GetMapping("/dataList")
    @Operation(summary = "获得订单完善资料列表")
    @Parameter(name = "id", description = "订单id", required = true, example = "1")
    @PreAuthorize("@ss.hasPermission('hutai:order:query')")
    public CommonResult<Map<String,List<UserTablesAuditDO>>> getOrderDataList(Long id) {
        Map<String,List<UserTablesAuditDO>> listMap = userTablesAuditService.getOrderDataList(id,1);
        return success(listMap);
    }

//    @GetMapping("/page")
//    @Operation(summary = "获得订单审核流程记录分页")
//    @PreAuthorize("@ss.hasPermission('hutai:order-process-record:query')")
//    public CommonResult<PageResult<OrderProcessRecordRespVO>> getOrderProcessRecordPage(@Valid OrderProcessRecordPageReqVO pageVO) {
//        PageResult<OrderProcessRecordDO> pageResult = orderProcessRecordService.getOrderProcessRecordPage(pageVO);
//        return success(OrderProcessRecordConvert.INSTANCE.convertPage(pageResult));
//    }
//
//    @GetMapping("/export-excel")
//    @Operation(summary = "导出订单审核流程记录 Excel")
//    @PreAuthorize("@ss.hasPermission('hutai:order-process-record:export')")
//    @OperateLog(type = EXPORT)
//    public void exportOrderProcessRecordExcel(@Valid OrderProcessRecordExportReqVO exportReqVO,
//              HttpServletResponse response) throws IOException {
//        List<OrderProcessRecordDO> list = orderProcessRecordService.getOrderProcessRecordList(exportReqVO);
//        // 导出 Excel
//        List<OrderProcessRecordExcelVO> datas = OrderProcessRecordConvert.INSTANCE.convertList02(list);
//        ExcelUtils.write(response, "订单审核流程记录.xls", "数据", OrderProcessRecordExcelVO.class, datas);
//    }

}
